/*                 		

This file contains main.


@author Vishwajeet Dusane
*/



#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h> 
#include<string.h>

#ifndef MAIN_H
#define MAIN_H

#include "Line.h"
#include "Color.h"
#include "Object2DTranformation.h"
#include "Object3DTranformation.h"
#include "Matrix.h"
#include "Rectangle.h"
#include "xLibEvent.h"
#include "Cube.h"
#endif
//#include "MyDisplay.h"


using namespace std;



/*
 * function: handle_expose. handles an Expose event by redrawing the window.
 * input:    display, 2 GCs, XExposeEvent event structure, dimensions of
 *           the window, pixels array.
 * output:   none.
 */
void
handle_expose(Display* display, GC gc, GC rev_gc, XExposeEvent* expose_event,
              unsigned int win_width, unsigned int win_height,
	      Window win);


/*
 * function: handle_drag. handles a Mouse drag event - if the left button
 *           is depressed - draws the pixel below the mouse pointer. if the
 *           middle button is depressed - erases the pixel below the mouse
 *           pointer.
 * input:    display, 2 GCs, XButtonEvent event structure, dimensions of
 *           the window, pixels array.
 * output:   none.
 */
void
handle_drag(Display* display, GC gc, GC rev_gc, XButtonEvent* drag_event,
            unsigned int win_width, unsigned int win_height
            );

/*
 * function: handle_button_down. handles a Mouse press event - if the left
 *           button is depressed - draws the pixel below the mouse pointer.
 *           if the middle button is depressed - erases the pixel below the
 *           mouse pointer.
 * input:    display, 2 GCs, XButtonEvent event structure, dimensions of
 *           the window, pixels array.
 * output:   none.
 */

void
handle_button_down(Display* display, GC gc, GC rev_gc,
                   XButtonEvent* button_event,
                   unsigned int win_width, unsigned int win_height
                   );
		   
		   
//GUI for transformation		   
void drawButton(int pressedButton = 1,int option = 1);
//drawing text in that button	
void drawText(int option = 1);
//convert integer number  to string and return pointer to string
char * itoa(int number);

void plotObject();

char getDropAxis();
   		   
		   
struct Axis{ bool x , y, z; short cnt; int xVal,yVal,zVal;} axis;
MyDisplay show;		   		   

  


Line xAxis(show),yAxis(show);   
Color color(show,1,0,0); 

   
 //Rectangle r1("Rectangle.txt",show);
 Cube c1("Cube.txt",show);
 
 Rectangle r1("Rectangle.txt",show);
 
 Object2DTransformation o2d("Rectangle.txt");
 
 Object3DTransformation o3d("Cube.txt");
 
 Matrix Pz("ProjectedMatrix.txt");
      
 Matrix T(4,4);
 
 int option=1;
 int pressedButton =1;  

int main(int argc,char *argv[])
{
 
   int x1,y1,y2,x2;
   
   //Matrix T("TransformationMatrix.txt");
   
   //Object2DTransformation line2D(2,2);
   
    if(argc == 5 ){
       
      x1=atoi(argv[1]);    
      y1=atoi(argv[2]);
      x2=atoi(argv[3]);
      y2=atoi(argv[4]); 

      
            
       
  
      
      Line l1(show);   
      
      
     //     line2D[0][0] = l1.x1;	
     //	  line2D[0][1] = l1.y1;
	  
     //     line2D[1][0] = l1.x2;
	  //  x1 = l1.x2;
     //     line2D[1][1] = l1.y2;
	   // y1  = l1.y2;

      Color backColor(show ,(short) 1 ,(short) 0 ,(short)0);
    //  Color foreColor(show ,(short) 0 ,(short) 0 ,(short)1);
      
      //Color c(l1.show.getDisplay(), l1.show.getGC(),1,0,0);    
      //cout<<"about to aloocate backgound color\n";
      backColor.setBackgroundColor(255,255,255);
       //backColor.setForegroundColor(0,100,0);
       //c.setBackgroundColor(50,0,0);
      //c.setBackgroundColor((short) 1 ,(short) 0 ,(short)0);
      //foreColor.setForegroundColor((short) 0 ,(short) 0 ,(short)50); 
      
      
      Line xAxis(show);
      Line yAxis(show);
      
      
      
    //  xAxis.drawLine();
    //  yAxis.drawLine();
      
    
    cout<<"X1 = "<<x1<<" y1 = "<<y1<<" x2 =  "<<x2<<" y2= "<<y2<<endl; 
      l1.setX1Y1(x1,y1);
      l1.setX2Y2(x2,y2); 
     backColor.setForegroundColor(0,0,255);
        l1.drawLine(); 
      
      backColor.setForegroundColor(255,0,0);
        xAxis.drawLine(0,-512,0,512); 
      backColor.setForegroundColor(255,0,0);	
      yAxis.drawLine(-512,0,512,0); 
      
      //Transformation of line begins here
        
      
	  
        //T.disp(); 	  
        //cout<<"Caling tranformation";
      
   //     line2D.transform(T);
   
    //   int i=0;  
  //      while(1){	
	
	//line2D.rotate((double) 90 * (((double)22/7) / 180) );  // should be in radians
	
	//line2D.scale(2,2);
	
	
	//line2D.save("TransformedObject.txt");
      
       //Line l2((int)line2D.transformedObject[0][0],(int)line2D.transformedObject[0][1],
        //       (int)line2D.transformedObject[1][0],(int)line2D.transformedObject[1][1] );      
	
	//double x,y;
	
	 //x=line2D.transformedObject[0][0];
	 //y=line2D.transformedObject[1][0];
	
	//line2D.transformedObject->save("temp.txt");
	
	//l1.setCoordinates("TransformedObject.txt");
	
	//l1.setX2Y2(x1,y1);
	//l1.drawLine();        
	
	//l1.setX2Y2();
        //l1.drawLine();
	
	
	 //if(i>=360) break;  //rotation loop condition
	 //i=i+30;            //roation loop increment
	 
	 
	 //line2D[0][0] = l1.x1;	//rotation loop
	 //line2D[0][1] = l1.y1;        //rotation loop 
	  
          //line2D[1][0] = l1.x2;
	       //  x1 = l1.x2; rotation  loop
	  //line2D[1][1] = l1.y2;
	   // y1  = l1.y2;   rotation loop
	    
	    
	    
	    

        //}	    
      getchar();
      
    }else{
     
     
     axis.cnt = 2;
     axis.x=1;
     axis.y=1;
     axis.z=0;     
     axis.xVal = 1;   
     axis.yVal = 1;   
     axis.zVal = 1;     
    
    //Object2DTransformation line2D("Rectangle.txt");
    
   // Matrix T("TransformationMatrix.txt");

    color.setForegroundColor(255,0,0);
        xAxis.drawLine(0,-512,0,512); 
    color.setForegroundColor(255,0,0);	
       yAxis.drawLine(-512,0,512,0); 

       
       plotObject();



	drawButton(pressedButton,option);
	drawText(option);
    
    
    //color.setForegroundColor(50,50,50);	       
      //c1.draw();
      
            
     //for(int i = 10 ; i < 90 ; i= i+ 10){ 
    //  o3d.Axis = 1;
    
        //T = o3d.getRotationMatrix(60,'y') * o3d.getRotationMatrix(45,'x') * Pz ;
	 
	// T.disp();
	  


      color.setForegroundColor(0,0,255);
      
           
      //c1.draw(o3d.getTransformedObject());
      //c1.draw(o3d.transform(T));
      //line2D.scale(2,2);
      
     //line2D.rotate((double) 90 * (((double)22/7) / 180));
//       line2D.sheare(2);
     // line2D.transform(T);  
            
      //line2D.save("TransformedObject.txt");
    
      //color.setForegroundColor(0,0,255);	         
      
     //   r1.draw(line2D.getTransformedObject());

     
  //EVENT HANDLING STARTS FROM HERE 


      /* subscribe to the given set of event types. */
  XSelectInput(show.display, show.win, ExposureMask | KeyPressMask |
                     ButtonPressMask | Button1MotionMask |
		     Button2MotionMask | StructureNotifyMask);

  /* perform an events loop */
  {
    int done = 0;
    XEvent an_event;
    while (!done) {
      XNextEvent(show.display, &an_event);
      switch (an_event.type) {
        case Expose:
	
	color.setForegroundColor(128,128,128);
          /* redraw our window. */
	  handle_expose(show.display, show.gc, show.gc, (XExposeEvent*)&an_event.xexpose,
             		show.displayWidth, show.displayHeight, show.win);
          break;
  
        case ConfigureNotify:
          /* update the size of our window, for expose events. */
          show.displayWidth = an_event.xconfigure.width;
          show.displayHeight = an_event.xconfigure.height;
          break;
  
        case ButtonPress:
          /* invert the pixel under the mouse pointer. */
          handle_button_down(show.display, show.gc, show.gc,
                             (XButtonEvent*)&an_event.xbutton,
                             show.displayWidth, show.displayHeight);
          break;
  
        case MotionNotify:
          /* invert the pixel under the mouse pointer. */
          handle_drag(show.display, show.gc,show.gc,
                      (XButtonEvent*)&an_event.xbutton,
                      show.displayWidth, show.displayHeight);
	  break;
  
        case KeyPress:
          /* exit the application by braking out of the events loop. */
          done = 1;
          break;
  
        default: /* ignore any other event types. */
          break;
      } /* end switch on event type */
    } /* end while events handling */
  }
      
  show.closeDisplay();  
//    getchar();
    //}
   }
    
 return 0;	
}//end of main










void
handle_expose(Display* display, GC gc, GC rev_gc, XExposeEvent* expose_event,
              unsigned int win_width, unsigned int win_height, Window win
	      )
{
  
	/* if this is the first in a set of expose events  ignore this event. */
	if (expose_event->count != 0)
	return;

	cout << "in handle expose event"<<endl;


	
	color.setForegroundColor(144,62,15);
		xAxis.drawLine(0,-512,0,512); 
		

	color.setForegroundColor(144,62,15);	
		yAxis.drawLine(-512,0,512,0); 

	color.setForegroundColor(55,67,144);		

	plotObject();



	drawButton(pressedButton,option);
	drawText(option);
   
     
}



void
handle_drag(Display* display, GC gc, GC rev_gc, XButtonEvent* drag_event,
            unsigned int win_width, unsigned int win_height
            )
{
  
    
    

   cout <<"insight handle drag event"<<endl;

}



void
handle_button_down(Display* display, GC gc, GC rev_gc,
                   XButtonEvent* button_event,
                   unsigned int win_width, unsigned int win_height
                   )
{
  int x, y;
  
  /* invert the pixel under the mouse. */
  x = button_event->x;
  y = button_event->y;
  switch (button_event->button) {
    case Button1: /* draw the given pixel in black color. */
          if((x>0 && y>0) && (x<200 && y<40)){
	     pressedButton = 1; 
	     
	     drawButton(pressedButton,option);
	     drawText(option);
	     
	  }else
	  if((x>200 && y>0) && (x<400 && y<40)){
	     pressedButton = 2;
	     
	     drawButton(pressedButton,option);
	     drawText(option);
	  }else
	  if((x>400 && y>0) && (x<600 && y<40)){
	     if(option == 2) option = 1;  
	     pressedButton =3;
	     
	     drawButton(pressedButton,option);
	     drawText(option);
	     
	  } else
	  if((x>600 && y>0) && (x<800 && y<40)){
	  
	     pressedButton = 4;
	     
	     drawButton(pressedButton,option);
	     drawText(option);
	     
	  }else
	  if((x>800 && y>0) && (x<1000 && y<40)){
	    
	    if(option == 1 ){
	    option = 2;
	    pressedButton = 1;
	    }
	    	
	    drawButton(pressedButton,option);
	    drawText(option);
	    
	    color.setForegroundColor(255,255,255);	 
	    
	    XFillRectangle(show.display,show.win,show.gc,600,0,200,40);
            XFillRectangle(show.display,show.win,show.gc,800,0,200,40);    
	    
            XDrawLine(show.display, show.win, show.gc, 1000,0, 1000, 40);
            XDrawLine(show.display, show.win, show.gc, 600,40, 1000, 40);
   
	  }  
	  
	  
	  
       // selection of plane
	  if((x>0 && y > 64) && (x<30 && y < 70)){
	     axis.cnt = 2;
	     axis.x = 1;
	       if(axis.y == 1 && axis.z == 1)  
	         axis.z = 0;
	    drawText(option);	 
	  }else
	  if((x>0 && y>71) && (x<30 && y< 77)){
	     axis.cnt = 2;
	     axis.y = 1;
	       if(axis.x == 1 && axis.z == 1)  
	         axis.x = 0;
	     drawText(option);	 
	  }else
	  if((x>0 && y>83) && (x<30 && y<89)){
	     axis.cnt = 2;
	     axis.z = 1;
	       if(axis.x == 1 && axis.y == 1)  
	         axis.y = 0;
	     drawText(option);	 
	  }
	  
	  
      //for incrementing x - axis 
          if((x>90 && y>50) && (x<110 && y<60)){
	     axis.xVal ++;
	     //NEED TO : apply printing of number then remove comment
	     //drawText(option);	 
	  }else
      //for  decrementing x - axis 	  
	  if((x>130 && y>50) && (x<150 && y<60)){
	     axis.xVal --;
	     //drawText(option);	 
	  }else
      //for incrementing y - axis 
          if((x>90 && y>70) && (x<110 && y<80)){
	     axis.yVal ++;
	     //drawText(option);	 
	  }else
      //for  decrementing y - axis 	  
	  if((x>130 && y>70) && (x<150 && y<80)){
	     axis.yVal --;
	     //drawText(option);	 
	  }else
      //for incrementing z - axis 
          if((x>90 && y>100) && (x<110 && y<110)){
	     axis.zVal ++;
	     //drawText(option);	 
	  }else
      //for  decrementing z - axis 	  
	  if((x>130 && y>100) && (x<150 && y<110)){
	     axis.zVal --;
	     //drawText(option);	 
	  }
       cout<<" x = " <<axis.xVal<<" y = " <<axis.yVal<<" z = " <<axis.zVal<<endl; 
      // Now, if plot is pressed 
          if((x>0 && y>120) && (x<40 && y<140)){
	  
	    plotObject();  
	   
	  } 

	   
          cout<<"Button 1 is pressed"<<endl;
    
         break;
    case Button2: /* draw the given pixel in white color. */
        cout<<"Button 2 is pressed"<<endl;
        break;
  }
}



void drawButton(int pressedButton,int option){



   color.setForegroundColor(199,199,199);

   switch(option){
   
   case 1:   
        if(pressedButton == 1)  color.setForegroundColor(129,129,129);
   	   XFillRectangle(show.display,show.win,show.gc,0,0,200,40);
	
	 color.setForegroundColor(199,199,199);  
	if(pressedButton == 2)  color.setForegroundColor(129,129,129);
 	   XFillRectangle(show.display,show.win,show.gc,200,0,200,40);
	   
	  color.setForegroundColor(199,199,199); 
	if(pressedButton == 3)  color.setForegroundColor(129,129,129);
	   XFillRectangle(show.display,show.win,show.gc,400,0,200,40);
	   
	  color.setForegroundColor(199,199,199);
	if(pressedButton == 4)  color.setForegroundColor(129,129,129);
	   XFillRectangle(show.display,show.win,show.gc,600,0,200,40);
	   
	  color.setForegroundColor(199,199,199);
	if(pressedButton == 5)  break;
	   XFillRectangle(show.display,show.win,show.gc,800,0,200,40);
	   

	
	
   color.setForegroundColor(0,0,0);	
	 XDrawLine(show.display, show.win, show.gc, 0,0, 0, 40);
	 XDrawLine(show.display, show.win, show.gc, 200,0, 200, 40);
	 XDrawLine(show.display, show.win, show.gc, 400,0, 400, 40);
	 XDrawLine(show.display, show.win, show.gc, 600,0, 600, 40);
         XDrawLine(show.display, show.win, show.gc, 800,0, 800, 40);
	 XDrawLine(show.display, show.win, show.gc, 1000,0, 1000, 40);
	 XDrawLine(show.display, show.win, show.gc, 0,40, 1000, 40);
	 
	 break;
	 
    case 2:
          if(pressedButton == 1)  color.setForegroundColor(129,129,129);
   	   XFillRectangle(show.display,show.win,show.gc,0,0,200,40);
	
 	 color.setForegroundColor(199,199,199);  
 	if(pressedButton == 2)  color.setForegroundColor(129,129,129);
 	   XFillRectangle(show.display,show.win,show.gc,200,0,200,40);
	   
	  color.setForegroundColor(199,199,199); 
	if(pressedButton == 3)  color.setForegroundColor(129,129,129);
	   XFillRectangle(show.display,show.win,show.gc,400,0,200,40);
 
        color.setForegroundColor(0,0,0);	
	 XDrawLine(show.display, show.win, show.gc, 0,0, 0, 40);
	 XDrawLine(show.display, show.win, show.gc, 200,0, 200, 40);
	 XDrawLine(show.display, show.win, show.gc, 400,0, 400, 40);
	 XDrawLine(show.display, show.win, show.gc, 600,0, 600, 40);
         XDrawLine(show.display, show.win, show.gc, 0,40, 600, 40);
	
	 break; 	 
    }	 
    
    
      color.setForegroundColor(199,199,199); 
       
       // x,y & z axis button       
       XFillRectangle(show.display,show.win,show.gc,0,50,80,20);
       XFillRectangle(show.display,show.win,show.gc,0,70,80,20);
       XFillRectangle(show.display,show.win,show.gc,0,90,80,20);
       
       //this is for "+"
       XFillRectangle(show.display,show.win,show.gc,90,50,10,10);
       //this is for "-"
       XFillRectangle(show.display,show.win,show.gc,130,50,10,10);
       //this is for "+"
       XFillRectangle(show.display,show.win,show.gc,90,70,10,10);
       //this is for "-"
       XFillRectangle(show.display,show.win,show.gc,130,70,10,10);   
       //this is for "+"
       XFillRectangle(show.display,show.win,show.gc,90,90,10,10);
       //this is for "-"
       XFillRectangle(show.display,show.win,show.gc,130,90,10,10); 	 
       
       //This is for "plot"
       XFillRectangle(show.display,show.win,show.gc,0,120,40,20);
}


void drawText(int option){

XFontStruct* font_info;       /* Font structure, used for drawing text.    */
  char* font_name = "*-helvetica-*-12-*"; /* font to use for drawing text.   */
  
  /* try to load the given font. */
  font_info = XLoadQueryFont(show.display, font_name);
  if (!font_info) {
      fprintf(stderr, "XLoadQueryFont: failed loading font '%s'\n", font_name);
      exit(-1);
  }

  /* assign the given font to our GC. */
  XSetFont(show.display, show.gc, font_info->fid);

  {
    /* variables used for drawing the text strings. */
    int x, y;
    char* text_string;
    int string_width;
    int font_height;

    /* find the height of the characters drawn using this font.        */
    font_height = font_info->ascent + font_info->descent;
    switch(option){
    case 1:
        color.setForegroundColor(0,0,0);
	text_string = "TRANSFORM";
	x = 20;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));


	text_string = "ROTATE";
	x = 220;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));

	text_string = "SCALE";
	x = 420;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));

	text_string = "SHEAR";
	x = 620;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));

	text_string = "PROJECTION";
	x = 820;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
	break;
	
    case 2:
        color.setForegroundColor(0,0,0);
        text_string = "PERSPECTIVE PROJECTION";
	x = 20;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));


	text_string = "PARALLEL PROJECTION";
	x = 220;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));

	text_string = "BACK 2 TRANSFORMATION";
	x = 420;
	y = font_height;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
        break;
     }	
     
     char *val;
     
     if( axis.cnt == 3 ) axis.z = 0;
     
     color.setForegroundColor(0,0,0);
      if(axis.x == 1 )color.setForegroundColor(144,62,15); 
      
      cout<<"Begin critical region: "<<axis.xVal<<endl;
        text_string = "x-axis = ";
// LATER WE MODIFY THIS, SO THAT VALUES WILL BE PRINTED ON THE SCREEN   	
//	val = itoa(axis.xVal);
//	cout<<"val in drawing : "<<val<<endl;
//	text_string = strcat(text_string,val);
	
	x = 0;
	y = font_height + 50;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));

     color.setForegroundColor(0,0,0);
      if(axis.y == 1) color.setForegroundColor(144,62,15);	
     
	text_string = "y-axis = ";
	x = 0;
	y = 2*font_height + 50 ;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));

     color.setForegroundColor(0,0,0);
      if(axis.z == 1) color.setForegroundColor(144,62,15);	
     
	text_string = "z-axis = ";
	x = 0;
	y = 3*font_height + 50;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
	
	
	
       color.setForegroundColor(0,0,0);
       text_string = "+";
	x = 91;
	y = 58;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));

       text_string = "-";
	x = 131;
	y = 58;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
	
	text_string = "+";
	x = 91;
	y = 78;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
	
	text_string = "-";
	x = 131;
	y = 78;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
	
	text_string = "+";
	x = 91;
	y = 98;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
 
	text_string = "-";
	x = 131;
	y = 98;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
	
        text_string = "PLOT";
	x = 0;
	y = 135;
	//cout <<"Font height = "<<y<<endl;
	XDrawString(show.display, show.win, show.gc, x, y, text_string, strlen(text_string));
 
  }

}


char * itoa(int number){

   char *str , *newStr;
   
   int tempRem = 0;
   cout<<"Insight  itoa "<<endl;
   str[0] = '\0';
   for(int i=0; ;i++){
    
     number = number / 10;
     tempRem = number % 10;
     
       switch (tempRem){
       
         case 1 : 
	        str[i] = '1';
                break ; 
         case 2 : 
	        str[i] = '2';  
                break ; 
         case 3 : 
	        str[i] = '3';  
                break ; 
         case 4 : 
	        str[i] = '4';  
                break ; 
         case 5 : 
	        str[i] = '5';  
                break ; 
         case 6 : 
	        str[i] = '6';  
                break ; 
         case 7 : 
	        str[i] = '7';  
                break ; 
         case 8 : 
	        str[i] = '8';  
                break ; 
         case 9 : 
	        str[i] = '9';  
                break ; 
         case 0 : 
	        str[i] = '0';  
                break ; 
	}
        
	if(number == 0){ str[i + 1] = '\0';   break; } 
   }
   
   cout<<" str in itoa : "<<str<<endl;
   int j = 0;
   for(int i = strlen(str), j =0 ;i>0;i--,j++){
   
       newStr[j] = str[i];       
   }
   
   newStr[strlen(str) + 1] = '\0';
   
   cout<<" newStr in itoa : "<<newStr<<endl;
   return newStr;
   
}


void plotObject(){


color.setForegroundColor(255,255,255);
 
 //r1.draw();
 c1.draw();
 
   switch(option){
   
     // transformation, scaling,rotation or shearing
     case 1: 
            r1.draw();           
            switch(pressedButton){
	    
	     // Transform Object
	     // put any 2d object here 
	     // 3d could b dangerous 
	      case 1:
	          color.setForegroundColor(0,0,0);
	          c1.draw(o3d.transform(axis.xVal,axis.yVal,axis.zVal));
	          break; 
		  
	     // Roatation Of object 	  
	       case 2: 	  
	        // check this 
		// not working properly
                   
	          
		  //c1.draw(o3d.rotate(axis.yVal + 10 ,'y'));
		  //c1.draw(o3d.rotate(axis.zVal + 10 ,'z'));
		  
		              if(getDropAxis() == 'x'){
					color.setForegroundColor(0,0,0); 
					c1.draw(o3d.rotate(axis.xVal*10,'x'),'x');
		    
		  
			      }else
		 		if(getDropAxis() == 'y'){
				        color.setForegroundColor(0,0,0); 
					c1.draw(o3d.rotate(axis.yVal*10,'y'),'y');
		    
			 	}else
				if(getDropAxis() == 'z'){
 					color.setForegroundColor(0,0,0); 
					c1.draw(o3d.rotate(axis.zVal*10,'z'),'z');
		    
				}
	          break; 
	       
	     //  Scaling 
	     // problem during shrinking
	       case 3 :
	       
	            color.setForegroundColor(0,0,0);
	            c1.draw(o3d.scale(axis.xVal,axis.yVal,axis.zVal)*Pz);
	          break;  
	     
	     // shearing 
	        case 4 : 
		   
                  color.setForegroundColor(0,0,0);
	          c1.draw(o3d.sheare(axis.xVal ,axis.yVal,axis.zVal));
	          break;  
  
	    }
             break;     
   
	 // projection      
       case 2: 
       
       
           switch(pressedButton){
          // perspective projection 
           case 1 :
	   
	   
                   break;
		   
	 // parallel projection 
	 
	    case 2 :
	    
	         if(getDropAxis() == 'x'){
		    Matrix Px = Pz;
		    Px[2][2] = 1;
		    Px[0][0] = 0;
		    
		   color.setForegroundColor(0,0,0); 
		   T = o3d.getRotationMatrix(axis.zVal + 10,'z') * o3d.getRotationMatrix(axis.yVal + 10 ,'y') * Px;
		   c1.draw(o3d.transform(T));
		    
		  
		 }else
		 if(getDropAxis() == 'y'){
                   Matrix Py = Pz;
		    Py[2][2] = 1;
		    Py[1][1] = 0;
		    
		    color.setForegroundColor(0,0,0);
		    T = o3d.getRotationMatrix(axis.zVal + 10 ,'z') * o3d.getRotationMatrix(axis.xVal + 10 ,'x') * Py;
		    c1.draw(o3d.transform(T));
		 
		 }else
		 if(getDropAxis() == 'z'){
		 
		 
		   color.setForegroundColor(0,0,0);
		   T = o3d.getRotationMatrix(axis.yVal + 10 ,'y') * o3d.getRotationMatrix(axis.xVal + 10 ,'x') * Pz;
		   c1.draw(o3d.transform(T));
		   
		 }
	   }	    
   } 





}


char getDropAxis(){

   if(axis.x == 0) { cout<<"X-axis is dropped \n "; return 'x';}
   if(axis.y == 0) { cout<<"Y-axis is dropped \n "; return 'y';}
   if(axis.z == 0) { cout<<"Z-axis is dropped \n "; return 'z';}

  return 'z';
}
